//
//  HWWebViewController.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/2/11.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit
import WebKit
class HWWebViewController: HWBaseViewController {
    var titleString = "公告"
    var urlString = ""
    var webView:WKWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        
        initUI()
        
        initFrame()
    }
    
}

extension HWWebViewController {
    private func initUI() -> Void {
        navigationView.titleLabel.text = titleString
        
        let config = WKWebViewConfiguration()
        //        config.applicationNameForUserAgent = "92tx_peiwan_App"
        webView = WKWebView(frame: .zero, configuration: config)
        webView.uiDelegate = self
        webView.navigationDelegate = self
        view.addSubview(webView)
        
        //        webView.evaluateJavaScript("navigator.userAgent") { message, error in
        //            print(message as Any)
        //        }
        
        //        let requesturl = URL(string: urlString)
        let request = URLRequest(url: URL(string: urlString)!)
        //        let  request  =   NSMutableURLRequest(url: requesturl!, cachePolicy: NSURLRequest.CachePolicy.useProtocolCachePolicy, timeoutInterval: 60)
        //        let tStr = Date().timeStamp
        //        let signature = "nnmitu"+tStr
        //
        //        let json = ["usersid":HWLocallyData.getUsersID(),"timestamp":tStr,"signature":signature.DDMD5Encrypt(.lowercase32)]
        //        let jsonString = HWPublicFuncTools.convertDictionAryToJson(dic: json as NSDictionary)
        //        aesString = aesEncryptString(jsonString, "NrrynIXcpucYvGSk")
        //        request.setValue(aesString, forHTTPHeaderField: "aes")
        //        request.setValue(tStr, forHTTPHeaderField: "ts")
        //        request.setValue(HWLocallyData.getUsersID(), forHTTPHeaderField: "uid")
        webView.load(request)
    }
    
    private func initFrame() -> Void {
        webView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(navigationView.snp.bottom)
        }
    }
}

extension HWWebViewController:WKUIDelegate,WKNavigationDelegate {
    
}
